package com.aduerr.v1shouyin.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * 类名: Versionutil
 * 此类用途: ---
 *
 * @Author: peixi
 * @Date: 2018-01-15 18:19
 * @Email: cr7inmanchester.com
 * @FileName: com.aduer.shouyin.util.Versionutil.java
 */
public class Versionutil {
    public static String getVersionName(Context context) {
        // 获取packagemanager的实例
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = null;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        } catch(PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return "1.0.0";
        }
        String version = packInfo.versionName;
        return version;
    }
}
